import createAxios from '/@/utils/axios'
import { useAdminInfo } from '/@/stores/adminInfo'
import { userInfo } from '/@/utils/interface/index'
import { encryption } from '/@/utils/common'

export const url = '/polarDay/'

export function login(method: 'get' | 'post', params: userInfo) {
    const user = encryption({
        data: params,
        key: import.meta.env.VITE_API_KEY,
        param: ['password'],
    });
    const paramsNew = {
        loginName: user.username,
        password: user.password,
        grant_type: 'password',
        scope: import.meta.env.VITE_SCOPE,
        client_id: import.meta.env.VITE_CLIENT_ID,
        client_secret: import.meta.env.VITE_CLIENT_SECRET
    };
    return createAxios({
        url: url + 'login',
        data: paramsNew,
        method: method,
    })
}

export function logout() {
    const adminInfo = useAdminInfo()
    return createAxios({
        url: url + 'logout',
        method: 'POST',
        data: {
            refreshToken: adminInfo.getToken('refresh'),
        },
    })
}
